package com.atm.simulation.bankSim;

import java.util.Date;

//远程服务器
public class AccountServiceSim {

private AccountList accountList = new AccountList();
	
	// 根据卡号获得账户实例
	public Account getAccountByCardNo(String cardNo){
		return accountList.getAccountByCardNo(cardNo);
	}
	
	// 验证卡号跟密码是否正确
	public Message verification(String cardNo, String password) {
		Account account = getAccountByCardNo(cardNo);
		Message message;
		Date date = new Date();
		if (password!=null && password.equals(account.getPassword())) {
			message = new Message(true, account, date);
		} else {
			message = new Message(false, "密码错误，请重新输入！", date);
		}
		return message;
	}
	
	// 取款操作
	public Message withdrawal(String cardNo, int amount) {
		Account account = getAccountByCardNo(cardNo);
		Message message;
		Date date = new Date();
		if (amount <= account.getAmount()) {
			int balance = account.getAmount() - amount;
			account.setAmount(balance);
			System.out.println("提款" + amount + "元");
			System.out.println("账户余额：" + account.getAmount() + "元");
			message = new Message(true, account, date);
		} else {
			System.out.println("取款金额超过账户余额！");
			message = new Message(false, "账户余额不足提现！", date);
		}
		return message;
	}
}
